# extrac from string
#author ruoyan han
source("D:\\git_file\\my_r_code\\R\\my_r_function\\union_TF.R")
extract_from_string <- function(
  input = "",
  extract_element = c()
){
  if(length(extract_element) == 0){
    cat("请好好填写抽取元素，默认返回原字符串加空字符串\n")
    cat("返回  ",input," _空字符串_\n")
    return(c(input, ""))
  }
  digts_temp <- nchar(input)
  clean_mark <- rep(0, digts_temp)
  single_unit_temp <- c()
  for(i in 1:digts_temp){
    if(except_TF(grepl(substr(input, i, i), extract_element, fixed = T))){
      clean_mark[i] <- 1
    }
    single_unit_temp <- c(single_unit_temp, substr(input, i, i))
  }
  if(sum(clean_mark)==0){
    cat("未找到匹配字符，返回原字符串加空字符串\n")
    cat("返回  ",input," _空字符串_\n")
    return(c(input, ""))
  }
  output1 <- ""
  output2 <- ""
  for(i in 1:digts_temp){
    if(clean_mark[i] == 0){
      output1 <- paste(output1, single_unit_temp[i], sep = "")
    }else{
      output2 <- paste(output2, single_unit_temp[i], sep = "")
    }
  }
  cat("已完成剪切\n")
  cat("返回  ",output1,output2," \n")
  return(c(output1, output2))
}

####Testing Area####
# 
# extract_from_string(input = "a3cde66.87ef6", extract_element = c("9", "3", "."))
# extract_from_string(input = "3.14", extract_element = c("=", "\\", "\""))
# 
# grepl(substr(input, i, i), extract_element)
# grepl(substr(input, i, i), extract_element, fixed = T)
# ?grepl
